package testy;

import java.awt.EventQueue;
 
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
 
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Desktop;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.List;
 
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
 
import java.awt.Color;
 
import javax.swing.JTabbedPane;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.ButtonGroup;
 
import testy.Data;
import testy.Question;
import testy.User;
 
import java.awt.GridLayout;
 
 
public class RFPgui {
 
        private JFrame 					frame;
        private LoginPanel 				mLoginPanel;
        private JTabbedPane 			mAdminPane;
        private JTabbedPane 			mAnalystPane;
        private AdminHomePanel			mAdminHomePanel;

        private JLabel label;
        private final Data dataBase;
        private List<Question> questionList;
        private JTextField textField;
        private JTextField adminQuestionInputText;
 
        /**
         * Launch the application.
         */
        public static void main(String[] args) {
                EventQueue.invokeLater(new Runnable() {
                        public void run() {
                                try {
                                        RFPgui window = new RFPgui();
                                        window.initialize();
                                } catch (Exception e) {
                                        e.printStackTrace();
                                }
                        }
                });
        }
 
        /**
         * Create the application.
         */
        public RFPgui() {
                dataBase = new Data();
                questionList = null;
        }
        
        private void initialize() {
        	frame = new JFrame();
        	frame.setLayout(null);
        	frame.setTitle("WhoopDeeWOCO");
        	frame.setResizable(false);
        	frame.setBounds(100, 100, 450, 300);
        	frame.getContentPane().setLayout(new CardLayout(0,0));
        	
        	
        	mLoginPanel = new LoginPanel(frame, dataBase);
        	frame.getContentPane().add(mLoginPanel, "LoginPanel");
        	
        	mAdminPane = new JTabbedPane(JTabbedPane.TOP);
        	mAnalystPane = new JTabbedPane(JTabbedPane.TOP);
        	frame.getContentPane().add(mAdminPane, "AdminPanel");
        	mAdminHomePanel = new AdminHomePanel(mLoginPanel, frame);
        	mAdminPane.addTab("AdminHomePanel", null, mAdminHomePanel, null);
        	frame.getContentPane().add(mAnalystPane, "AnalystPanel");
        	
        	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        	frame.getContentPane().setVisible(true);
        	frame.setVisible(true);
        	
        }
        
        public void logout() {
        	
        }
 
//        /**
//         * Initialize the contents of the frame.
//         */
//        
//        private void initialize() {
//                frame = new JFrame();
//                frame.setTitle("WhoopDeeWOCO");
//                frame.setResizable(false);
//                frame.setBounds(100, 100, 450, 300);
//                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//                frame.setVisible(true);
//                /* Login */
//                frame.getContentPane().setLayout(new CardLayout(0, 0));
//                JPanel loginDisplay = new JPanel();
//                frame.getContentPane().add(loginDisplay, "name_1417317733020304000");
//                loginDisplay.setLayout(null);
//               
//               
//                pinField = new JTextField("PIN");
//                pinField.setBounds(140, 154, 155, 28);
//                loginDisplay.add(pinField);
//                pinField.setColumns(10);
//               
//                passwordField = new JPasswordField("password");
//                passwordField.setBounds(140, 186, 155, 20);
//                loginDisplay.add(passwordField);
//               
// 
//               
//                JTabbedPane analystPane = new JTabbedPane(JTabbedPane.TOP);
//                frame.getContentPane().add(analystPane, "name_1417317733028506000");
//               
//                JPanel homePanel = new JPanel();
//                analystPane.addTab("Home", null, homePanel, null);
//                homePanel.setLayout(null);
//               
//                JButton btnOpen = new JButton("Open");
//                btnOpen.addActionListener(new ActionListener() {
//                        public void actionPerformed(ActionEvent e) {
//                                JFileChooser jf = new JFileChooser();
//                                jf.showOpenDialog(btnOpen);
//                                File file = jf.getSelectedFile();
//                                Desktop desktop = Desktop.getDesktop();
//                               
//                                try {
//                                        if (file !=  null)
//                                                desktop.open(file);
//                                } catch (IOException e1) {
//                                        // TODO Auto-generated catch block
//                                        e1.printStackTrace();
//                                }
//                        }
//                });
//                btnOpen.setBounds(164, 178, 103, 29);
//                homePanel.add(btnOpen);
//               
//                JButton btnNew = new JButton("New");
//                btnNew.addActionListener(new ActionListener() {
//                        public void actionPerformed(ActionEvent e) {
//                                File file = new File("blank.docx");
//                                Desktop desktop = Desktop.getDesktop();
//                               
//                                try {
//                                        desktop.open(file);
//                                } catch (IOException e1) {
//                                        // TODO Auto-generated catch block
//                                        e1.printStackTrace();
//                                }
//                        }
//                });
//                btnNew.setBounds(6, 178, 117, 29);
//                homePanel.add(btnNew);
//               
//                JLabel lblWelcome = new JLabel("Welcome");
//                lblWelcome.setBounds(187, 34, 137, 16);
//                homePanel.add(lblWelcome);
//               
//                JButton btnLogout = new JButton("Logout");
//                btnLogout.addActionListener(new ActionListener() {
//                        public void actionPerformed(ActionEvent e) {
//                                CardLayout c = ((CardLayout) (frame.getContentPane()).getLayout());
//                                c.show(frame.getContentPane(), "name_1417317733020304000");
//                                pinField.setText("");
//                                passwordField.setText("");
//                        }
//                });
//                btnLogout.setBounds(306, 178, 117, 29);
//                homePanel.add(btnLogout);
//               
//                JPanel searchPanel = new JPanel();
//                searchPanel.setToolTipText("Search");
//                analystPane.addTab("Search", null, searchPanel, null);
//                searchPanel.setLayout(null);
//               
//                JScrollPane scrollPane_2 = new JScrollPane();
//                scrollPane_2.setBounds(17, 6, 394, 163);
//                searchPanel.add(scrollPane_2);
//               
//                JScrollPane scrollPane_3 = new JScrollPane();
//                scrollPane_3.setBounds(17, 172, 290, 54);
//                searchPanel.add(scrollPane_3);
//               
//                JTextArea textArea = new JTextArea();
//                scrollPane_3.setViewportView(textArea);
//               
//                JTextArea txtrSearchdisplay = new JTextArea();
//                txtrSearchdisplay.setWrapStyleWord(true);
//                txtrSearchdisplay.setLineWrap(true);
//                scrollPane_2.setViewportView(txtrSearchdisplay);
//                txtrSearchdisplay.setEditable(false);
//               
//                JButton btnSearch = new JButton("Search");
//                btnSearch.setBounds(306, 168, 117, 29);
//                btnSearch.addActionListener(new ActionListener() {
//                        public void actionPerformed(ActionEvent e) {
//                                final String s = textArea.getText();
//                                questionList = dataBase.searchQuestions(s);
//                                if (questionList.size() > 0) {
//                                        StringBuilder sb = new StringBuilder();
//                                        for (Question q : questionList) {
//                                                sb.append(q.toString());
//                                        }
//                                        txtrSearchdisplay.setText(sb.toString());
//                                } else
//                                        txtrSearchdisplay.setText("NO RESULTS");
//                        }
//                });
//                searchPanel.add(btnSearch);
//               
//                JButton btnShowAll = new JButton("Show All");
//                btnShowAll.setBounds(306, 197, 117, 29);
//                btnShowAll.addActionListener(new ActionListener() {
//                        public void actionPerformed(ActionEvent e) {
//                                final String s = textArea.getText();
//                                questionList = dataBase.allQuestions();
//                                if (questionList.size() > 0) {
//                                        StringBuilder sb = new StringBuilder();
//                                        for (Question q : questionList) {
//                                                sb.append(q.toString());
//                                        }
//                                        txtrSearchdisplay.setText(sb.toString());
//                                } else
//                                        txtrSearchdisplay.setText("NO RESULTS");
//                        }
//                });
//                searchPanel.add(btnShowAll);
//               
// 
//               
//                JPanel proposePanel = new JPanel();
//                analystPane.addTab("Propose", null, proposePanel, null);
//                proposePanel.setLayout(null);
//               
//                JScrollPane scrollPane = new JScrollPane();
//                scrollPane.setBounds(23, 26, 373, 72);
//                proposePanel.add(scrollPane);
//               
//                JTextArea txtrQuestion = new JTextArea();
//                scrollPane.setViewportView(txtrQuestion);
//                txtrQuestion.setWrapStyleWord(true);
//                txtrQuestion.setLineWrap(true);
//               
//                JScrollPane scrollPane_1 = new JScrollPane();
//                scrollPane_1.setBounds(23, 123, 373, 72);
//                proposePanel.add(scrollPane_1);
//               
//                JTextArea txtrAnswer = new JTextArea();
//                scrollPane_1.setViewportView(txtrAnswer);
//               
//                JLabel lblQuestion = new JLabel("Question");
//                lblQuestion.setBounds(24, 6, 61, 16);
//                proposePanel.add(lblQuestion);
//               
//                JLabel lblAnswer = new JLabel("Answer");
//                lblAnswer.setBounds(23, 105, 61, 16);
//                proposePanel.add(lblAnswer);
//               
//                JButton btnSubmit = new JButton("Submit");
//                btnSubmit.addActionListener(new ActionListener() {
//                        public void actionPerformed(ActionEvent e) {
//                                Question q = new Question(txtrQuestion.getText(), "", txtrAnswer.getText());
//                               
//                                dataBase.insertProposedQuestion(q);
//                                txtrQuestion.setText("");
//                                txtrAnswer.setText("");
//                        }
//                });
//                btnSubmit.setBounds(150, 197, 117, 29);
//                proposePanel.add(btnSubmit);
//               
//                JTabbedPane adminPane = new JTabbedPane(JTabbedPane.TOP);
//                frame.getContentPane().add(adminPane, "name_1417317733035912000");
//               
//               
//                JPanel adminPropPanel = new JPanel();
//                adminPane.addTab("Proposed", null, adminPropPanel, null);
//                adminPropPanel.setLayout(null);
//               
//                JTextArea txtrProposed = new JTextArea();
//                txtrProposed.setEditable(false);
//                txtrProposed.setBounds(6, 24, 417, 169);
//                adminPropPanel.add(txtrProposed);
//               
//                JButton btnRefresh = new JButton("Refresh");
//                btnRefresh.addActionListener(new ActionListener() {
//                        public void actionPerformed(ActionEvent e) {
//                                questionList = dataBase.allProposed();
//                                if (questionList.size() > 0) {
//                                        StringBuilder sb = new StringBuilder();
//                                        for (Question q : questionList) {
//                                                sb.append(q.toString());
//                                                sb.append(q.getId());
//                                        }
//                                        txtrProposed.setText(sb.toString());
//                                } else
//                                        txtrProposed.setText("NO PROPOSED QUESTIONS AT THIS TIME");
//                        }
//                });
//                btnRefresh.setBounds(340, 197, 83, 29);
//                adminPropPanel.add(btnRefresh);
//               
//                JLabel lblProposedAnswersAnd = new JLabel("Proposed Answers and Questions");
//                lblProposedAnswersAnd.setBounds(19, 6, 241, 16);
//                adminPropPanel.add(lblProposedAnswersAnd);
//               
//                textField = new JTextField();
//                textField.setBounds(6, 196, 134, 28);
//                adminPropPanel.add(textField);
//                textField.setColumns(10);
//               
//                JButton btnAddProp = new JButton("Add");
//                btnAddProp.addActionListener(new ActionListener() {
//                        public void actionPerformed(ActionEvent e) {
//                                dataBase.updateProposed(Integer.parseInt(textField.getText()));
//                                textField.setText("");
//                        }
//                });
//                btnAddProp.setBounds(152, 197, 83, 29);
//                adminPropPanel.add(btnAddProp);
//               
//                JButton btnDelete = new JButton("Delete ID");
//                btnDelete.addActionListener(new ActionListener() {
//                        public void actionPerformed(ActionEvent e) {
//                               
//                        }
//                });
//                btnDelete.setBounds(245, 197, 83, 29);
//                adminPropPanel.add(btnDelete);
//               
//                JPanel addPanel = new JPanel();
//                adminPane.addTab("Add", null, addPanel, null);
//                addPanel.setLayout(null);
//               
//                JTextArea txtrQ = new JTextArea();
//                txtrQ.setBounds(22, 25, 386, 70);
//                addPanel.add(txtrQ);
//               
//                JLabel lblQuestion_1 = new JLabel("Question");
//                lblQuestion_1.setBounds(22, 6, 61, 16);
//                addPanel.add(lblQuestion_1);
//               
//                JTextArea txtrA = new JTextArea();
//                txtrA.setBounds(22, 124, 386, 70);
//                addPanel.add(txtrA);
//               
//                JLabel lblAnswer_1 = new JLabel("Answer");
//                lblAnswer_1.setBounds(22, 107, 61, 16);
//                addPanel.add(lblAnswer_1);
//               
//                JButton btnAdd = new JButton("Add");
//                btnAdd.addActionListener(new ActionListener() {
//                        public void actionPerformed(ActionEvent e) {
//                                String question = txtrQ.getText();
//                                String answer = txtrA.getText();
//                                Question q = new Question(question, question, answer);
//                                dataBase.insertQuestion(q);
//                                txtrQ.setText("");
//                                txtrA.setText("");
//                        }
//                });
//                btnAdd.setBounds(154, 197, 117, 29);
//                addPanel.add(btnAdd);
//               
//                JPanel adminQuestionPanel = new JPanel();
//                adminPane.addTab("Questions", null, adminQuestionPanel, null);
//                adminQuestionPanel.setLayout(null);
//               
//                JScrollPane scrollPane_4 = new JScrollPane();
//                scrollPane_4.setBounds(0, 0, 429, 180);
//                adminQuestionPanel.add(scrollPane_4);
//               
//                JTextArea adminQuestionText = new JTextArea();
//                adminQuestionText.setLineWrap(true);
//                scrollPane_4.setViewportView(adminQuestionText);
//               
//                JButton deleteBtn = new JButton("Delete ID");
//                deleteBtn.setBounds(168, 192, 117, 29);
//                adminQuestionPanel.add(deleteBtn);
//               
//                adminQuestionInputText = new JTextField();
//                adminQuestionInputText.setBounds(10, 191, 134, 28);
//                adminQuestionPanel.add(adminQuestionInputText);
//                adminQuestionInputText.setColumns(10);
//               
//                JButton btnRefresh_1 = new JButton("Refresh");
//                btnRefresh_1.setBounds(306, 192, 117, 29);
//                adminQuestionPanel.add(btnRefresh_1);
//               
//               
//                JButton loginButton = new JButton("Login");
//                loginButton.addActionListener(new ActionListener() {
//                        @Override
//                        public void actionPerformed(ActionEvent theEvent) {
//                               
//                                final String pinNumber = pinField.getText();
//                                final String password = passwordField.getText();
//                                //Verify to database.
//                                User temp = dataBase.tryLogin(Integer.parseInt(pinNumber), password);
//                                       
//                               
//                                if (temp != null && !temp.isAdmin()) {
//                                        CardLayout c = ((CardLayout) (frame.getContentPane()).getLayout());
//                                        c.show(frame.getContentPane(), "name_1417317733028506000");
//                                } else if (temp != null && temp.isAdmin()) {
//                                        CardLayout c = ((CardLayout) (frame.getContentPane()).getLayout());
//                                        c.show(frame.getContentPane(), "name_1417317733035912000");
//                                }
//                        }
//                });
//                loginButton.setBounds(161, 218, 117, 29);
//                loginDisplay.add(loginButton);
//                frame.setLocationRelativeTo(null);
//        }
}